//设置session参数
function setSessionfunc(typeid,zid){
	//设置当前用户的session值
    //typeid 系统分类id (比如对应前端八大类), zid 当前用户的站点id
	var url="/bigscrenn/setUserSession?typeid="+typeid+"&zid="+zid;
    $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
              console.log(data,'参数');         
	     }
    		
    });	
};

$(function(){
	//地图切换开始
	$("#exchangeMap").click(function(){
		
		var index = layer.load(1, {   //iframe中地图加载完成走之前显示loading动画
		  shade: [0.1,'#fff']         //0.1透明度的白色背景
		});
		var $iFrame = $("#gdMap");
		$iFrame.prop("src", "./gaodeMap-intlgMonitor.html");
		$iFrame.load(function() {
			//alert("加载完毕");
			layer.close(index);      //iframe中地图加载完成走之后  关闭loading动画
		});
		$("#gaodeMapID").css("display","block");
		$("#closeGaodeBtn").css("display","block");
	})
	$("#closeGaodeBtn").click(function(){
		$("#gdMap").attr('src','');
		$(this).css("display","none");
		$("#gaodeMapID").css("display","none");
	})
	//地图切换結束
})

var yn_yhzb = 0,      //用户占比及分类占比
	yn_zxm_zsb = 0,   //总项目、总设备
	yn_glywpd = 0,    //各类运维派单
	yn_zhnhzb = 0,    //综合能耗占比
	yn_gjxx = 0,      //告警信息
	yn_glsgzb = 0,    //各类事故占比
	yn_xxfb = 0;	  //信息分布



vueFunc();
//过滤后的站点（用户）开始
function vueFunc(userid) {
	vm = new Vue({
		el: "#app",
		data: {
			kehu: [],
			unitList:[],
			typeid:"",//八大分类id
			
			seletUnitID:'',//选中的单位id
			seletUnitName:'',//选中的单位名称
		},
		mounted: function() {
			this.getSession();
			
			this.userNumFunc(this.userid);
            
			this.FGMJIFunc(this.userid,this.unitID);
            
			this.alarmTongjifunc(this.userid,this.unitID);
            
			this.warningMsgFunc(this.userid,this.unitID);
            
			this.upScrollFunc();
			
			this.unitListFunc(this.userid);
			this.duanduan();
			
			this.shuaxin();
		},
		methods: {
			//登录session
			getSession:function(){
				var vs = this;
				//var userid,unitID,userType;
				var url="/bigscrenn/getUserSession";
			     $.ajax({
				     cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     async: false,				   
				     success: function(data){
			     	     //alert("这是第二级sessionInfo="+data);
				    	 //js解析json串
			     	    var obj={};
			     	     if(data&&data!=null&&data!=undefined&&data!=''){
			     	    	obj = JSON.parse(data);
			     	     }

			             if (obj.session.length>0){
			                   /*alert(obj.session[0].UserID); //用户id
			                   alert(obj.session[0].Name);     //用户名称
			                   alert(obj.session[0].UnitID);   //用户单位id
			                   alert(obj.session[0].UserAuthority);//用户权限 2 所有单位 3 本单位
			                   alert(obj.session[0].typeid);   //系统分类id (比如对应前端八大类)
			                   alert(obj.session[0].zid);      //当前用户的站点id*/
			            	 //alert("对应前端八大类="+obj.session[0].typeid);
			            	   vs.userid = obj.session[0].UserID;
			 	  			   vs.unitID = obj.session[0].UnitID;
			 	  			   vs.userType = obj.session[0].UserAuthority;
			 	  			   vs.typeid = obj.session[0].typeid;
			            	 }
			                //alert("userid="+vs.userid+"and unitID="+vs.unitID+"and userType="+vs.userType) ;
			                //alert("单位名称="+obj.session[0].Name) ;
			                //vs.getzhandianFunc(vs.userid,vs.unitID);//调用站点方法
			                
				     }
			     });
			},
			
			//根据用户ID得到单位列表   userid 用户ID
			unitListFunc:function(userid){
				var vmUni = this;
				var url="/bigscrenn/getUnitList?userid="+userid; 
				var defer = $.Deferred();
				 $.ajax({
				     cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     //async: false,				   
				     success: function(data){
				    	 defer.resolve(data);
				           //alert(data);
				           console.log(data);
				           var dataObj=eval("("+data+")");//转换为json对象 
				           //alert(dataObj);
				     	  console.log(JSON.stringify(dataObj));
				          for (var i = 0; i < dataObj.rows.length; i++) {
				     		var name= dataObj.rows[i].UNITNAME;
				     		var value= dataObj.rows[i].UNITID;
				     		vmUni.unitList.push({"unitName":name,"unitID":value});
				     		//alert(name);
				     	  }
				          //console.log(vmUni.unitList,"智能监测单位列表");
				          
				          vmUni.$nextTick(function() {
								var firstZid= $("#dl>dd:first() >a").attr('cid');
								console.log("firstZid="+firstZid);
								
								console.log("li === " + $("li.layui-nav-item").length);
								$("li.layui-nav-item").first().addClass("layui-nav-itemed"); //默认第一个大用户展开
								var aArr = $(".layui-nav-child>dd>a");
								for(var i=0;i<aArr.length; i++){
								//	console.log("用户id===:"+aArr[i].attr("href"));
								}
								
								layui.use('element', function() {
									var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

									//监听导航点击
									element.on('nav(demo)', function(elem) {
										//console.log(elem)
										//alert(elem.text());
										//alert($(this).attr('cid'));
										localStorage.setItem("homeCID",$(this).attr('cid'));//存储当前点击的站点CID
										setSessionfunc("","","",$(this).attr('cid')+","+elem.text());                //选择站点设置session参数
										vmUni.zhanDianNumFunc(vmUni.userid,$(this).attr('cid'));
										//window.location.href = "specificHome.html"
										
									});
								});
							})
							
				     }
				 });
				 return defer.promise();
			},
			
			//单位下的站点数
			//更据单位ID获取站点数量   unitid 单位ID
			zhanDianNumFunc:function(userid,unitid){
				var vm_zd = this;
				//var url="/bigtongji/getUnitIDList?unitid="+unitid;//吴新接口
				var url="/bigscrenn/getSiteList?userid="+userid+"&unitid="+unitid;
				console.log("进来的单位下的站点数地址="+url);
				var defer = $.Deferred();
				 $.ajax({
				     cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     //async: false,				   
				     success: function(data){
				    	 defer.resolve(data);
		                   //alert(data);
		                   console.log(data);
		                   var dataObj=eval("("+data+")");//转换为json对象 
		                   //alert(dataObj);
		                   //alert(dataObj);
		                 	var total= dataObj.total;
		                 	vm_zd.zhanDianNum = total;
		                 	if(total==0){
		                 		//console.log("点击的单位下的站点数："+total);
		                 		layer.msg('这个单位没有站点');
		                 	}
		                 	if(total==1){
		                 		//alert("站点名称 = "+dataObj.rows[0].UNITNAME+" 站点id"+dataObj.rows[0].CID);
		                 		//console.log("点击的单位下的站点数："+total);
		                 		setSessionfunc('',dataObj.rows[0].CID+','+dataObj.rows[0].UNITNAME,'','');
		                 		window.location.href = "specificUser.html"
		                 	}if(total>1){
		                 		//console.log("点击的单位下的站点数："+total);
		                 		window.location.href = "specificHome.html"
		                 	}
		                 	//alert(total);
		             	  console.log(JSON.stringify(dataObj));
		                  for (var i = 0; i < dataObj.rows.length; i++) {
		             		var name= dataObj.rows[i].UNITNAME;
		             		var CID= dataObj.rows[i].CID;
		             		//alert(name);
		             	  }
		                  
		                //返回上一级跳转逻辑处理
						//var obj = {'yiji':'1','erji':'2'};
						var obj = {'erji':'2'};
				        var objStr = JSON.stringify(obj);
				        localStorage.setItem("urls",objStr);
		                  
				     }
				});
				 return defer.promise();
			},
			
			//===站点列表方法
			getzhandianFunc: function(userid,unitid) {
				var d = this;
				var url = "/bigscrenn/getSiteList?userid="+userid+"&unitid="+unitid;
				var defer = $.Deferred();
				 $.ajax({
					type: "POST",
					url:url,
					//async: false,
					success: function(result) {
						defer.resolve(result);
						//js解析json串
						//alert("用户选择列表 Url==="+url);
                        var obj = JSON.parse(result);
                        //alert(obj.total);
                        console.log("obj.rows==:"+obj.rows);
                        /*for (var i=0;i<obj.rows.length;i++)
                        {
                              alert("obj.rows[i].CID=="+obj.rows[i].CID);//站点id
                              //alert(obj.rows[i].UNITID);//站点对应的单位id 
                              //alert(obj.rows[i].UNITNAME);//站点名称
                              //alert(obj.rows[i].LONGITUDE);//站点经度
                              //alert(obj.rows[i].LATITUDE);//站点纬度
                        }*/
						d.kehu = obj.rows;
						console.log("这里动态绑定智能监测的跳转的链接:"+"specificUser.html?unitID="+obj.rows[0].UNITID);
						//$("#first").attr("href","intlgMonitor.html?unitID="+obj.rows[0].UNITID);//这里动态绑定智能监测的跳转的链接
						localStorage.setItem("unitid",obj.rows[0].UNITID);
						
						//alert(d.kehu.length);
						d.$nextTick(function() {
							console.log("li === " + $("li.layui-nav-item").length);
							$("li.layui-nav-item").first().addClass("layui-nav-itemed"); //默认第一个大用户展开
							var aArr = $(".layui-nav-child>dd>a");
							for(var i=0;i<aArr.length; i++){
							//	console.log("用户id===:"+aArr[i].attr("href"));
							}
							layui.use('element', function() {
								var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

								//监听导航点击
								element.on('nav(demo)', function(elem) {
									//console.log(elem)
									//alert(elem.text());
									//alert($(this).attr('cid'));
									setSessionfunc('',$(this).attr('cid'));
								});
							});
						})
						
					}
				});
				 return defer.promise();
			},
			//用户数饼图(得到用户数统计列表)
			userNumFunc:function(userid){
				//userid用户id,type站点分类，type有值时表示调用指定分类下的用户数，比如1智能监测2智能运维3工程管理4配售电管理，type为空时按分类统计，有值时按区域统计
			    var url="/bigscrenn/getUserStatistics?userid="+userid+"&type=1";
			    //alert("进来的用户数饼图地址url=:"+url);
			    var defer = $.Deferred();
				 $.ajax({
				     cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     //async: false,				   
				     success: function(data){
				    	 defer.resolve(data);
				    	   var JG_pieData = [];
                           //alert("用户数饼图数据=="+data);
                           //js解析json串
                           var obj = JSON.parse(data);
                           //alert(obj.total);//记录数
                           for (var i=0;i<obj.rows.length;i++){
                               //alert(obj.rows[i].NUM); //统计数据
                               //alert(obj.rows[i].NAME);//统计类别名称
                           }
                           if(obj != null && obj.rows.length > 0) {
               				//alert(obj.rows.length);
               				for(var i = 0; i < obj.rows.length; i++) {
               					var nl = {"name":obj.rows[i].NAME+obj.rows[i].NUM,"value":obj.rows[i].NUM};
               					JG_pieData.push(nl);
               				}
               				//alert("JG_pieData======"+JSON.stringify(JG_pieData));
               				JG_pieFunc(JG_pieData);
               			}
                           yn_yhzb = 1;
				     }
			     });
				 return defer.promise();
			},
			//覆盖面积饼状图
			FGMJIFunc:function(usersid){
				var pieName = [];
				var url = "/bigscrenn/getAcreageStatistics?userid="+usersid+"&type=1";
				console.log("覆盖面积饼状图 url==:"+url);
				var defer = $.Deferred();
				 $.ajax({
					 cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     //async: false,				   
				     success: function(data){
				    	 defer.resolve(data);
			           //alert("覆盖面积 = "+data);
			           //js解析json串
			           var obj = JSON.parse(data);
			           console.log("覆盖面积记录数=="+obj.total);//记录数
			           /*for (var i=0;i<obj.rows.length;i++){
			                 alert(obj.rows[i].NUM);//统计覆盖面积数据
			                 alert(obj.rows[i].NAME);//统计类别名称
			           }*/
						if(obj != null && obj.rows.length > 0) {
							for(var i = 0; i < obj.rows.length; i++) {
								var nl = {"name":obj.rows[i].NAME+obj.rows[i].NUM,"value":obj.rows[i].NUM};
								pieName.push(nl);
							}
							//bingFunc(pieName);//调用覆盖数方法
							//setTimeout("bingFunc('"+pieName+"')",600);
						}
					}
				});
				 return defer.promise();
			},
			// 向上推送向上文字结束
			//信息发布
			upScrollFunc: function(userID,unitid) {
				var ctext = [],fname=[];
			     var msg_ul = document.getElementById("msg_ul");
			     var defer = $.Deferred();
				 $.ajax({
			 		//url: "/static/bigdatashow/webProject/json/pro_home.json",
			 		url:"/bigscrenn/getInformation",
			 		cache: true,
			 	    type: "POST",
			 	    data:"",
			 	    //async: false,	
			 		dataType: "json",
			 		success: function(result) {
			 			defer.resolve(result);
			            console.log("推送消息数据===："+JSON.stringify(result));
			            console.log("total==:"+result.rows[0].DOCID);
			            //js解析json串
			            // var obj = JSON.parse(result);
			            console.log("推送消息详情==:"+result.rows.length);//记录数
			            for (var i=0;i<result.rows.length;i++)
			            {
			                  //alert(result.rows[i].DOCID);//id
			                  //alert(result.rows[i].DTITLE);//标题
			                  //alert(result.rows[i].DREMARK);//内容
			                  //alert(result.rows[i].CDATE);//发布时间
			            	  ctext.push(result.rows[i].DREMARK);
			            	  if(result.rows[i].fname!=undefined){
			            		  result.rows[i].fname=''
			            	  }
			            	  fname.push(result.rows[i].FNAME);
			            }
			            //alert("ctext = "+ctext.length);
			 			if(result.rows != null && result.rows.length > 0) {
			 				localStorage.setItem("upDataNum",result.rows.length);//用于弹框
			 				for(var i = 0; i < result.rows.length; i++) {
			 					$("#scPagemsg_ul").append("<li id="+result.rows[i].DOCID+"><p><a href='javascript:;' title="+result.rows[i].CDATE+'>' + result.rows[i].CDATE + "<a href='javascript:;' title="+result.rows[i].DTITLE+'>' + result.rows[i].DTITLE +""+ "</a></p></li>")
			 				}
			 			}
			 			var fujian = '';
			 			$("#scPagemsg_ul li").on('click',function(){
			 				var inedx = $(this).index();
			 				//alert("inedx = "+inedx + " $(this).id = "+$(this).attr('id'));
			 				//下载附件
			 				funDownload($(this).attr('id'));
			 				function funDownload(did){
			 					//alert(did);
			 				   var url='/pminfo/path';
			 				   var defer = $.Deferred();
			 				   $.ajax({
			 						type: "POST",
			 						url:url,
			 						data:{'did':did},
			 				        //async: false,
			 				        success: function(data) {
			 				        	defer.resolve(data);
			 				        	fujian = data;
			 					        //window.location.href =data;
			 					     }
			 				     });
			 				 }
			 				//alert("ctext[inedx] = "+ctext[inedx]);
			 				//自定页

			 				layer.open({
			 					title:"信息发布",
			 					center:"center",
			 					type: 1,
		 					    skin: 'layui-layer-rim', //加上边框
			 					area: ['720px', '340px'], //宽高
			 					//content: 'html内容',
			 					content: '<div style="padding:20px;">'+ctext[inedx]+'<br /><p id="a" style="color:#fff;">'+fname[inedx]+'<span style="color:#00ff0afa;cursor: pointer;">&nbsp; &nbsp;下载</span></p></div>',
			 				});
			 				$(".layui-layer-rim").css({
	       						'border':'none',
	       						'background':'#0055b3'
	       					});
			 				$(".layui-layer-rim p").css({
	       						'color':'#fff'
	       					});
			 				$(".layui-layer-rim a.layui-layer-ico").text('×').css({
        						'color':'#fff',
        						'fontSize':'2rem',
        						'margin-top': '-15px',
        						'background':'none'
        					});
			 				$("#a").on("click",function(){
			 					//alert(fujian)
			 					var Cts = fujian;
			 					//判断是图片文件还是非图片文件
			 					if(Cts.indexOf(".png") >= 0 || Cts.indexOf(".jpg") >= 0) {
			 						//alert('Cts中包含Text字符串');
			 						//页面层
			 						layer.open({
			 						  type: 1,
			 						  skin: 'layui-layer-rim', //加上边框
			 						  area: ['1000px', '800px'], //宽高
			 						  content: "<img style='width: 100%;' src='"+Cts+"'/>"
			 						});
			 					}else{
			 						window.location.href =Cts;
			 					}
			 				});
			 			})
			 		}
			 	});
				 return defer.promise();
			},
			//告警统计柱状图开始
			alarmTongjifunc:function(userid,unitid){
				var dataAxis = [],
				data = [];
				var yMax = 400;
				var dataShadow = [];
				var url = "/bigscrenn/getWarningStatistics?userid="+userid+"&type=1&unitid="+unitid;
				//alert("告警统计柱状图 url==:"+url);
				
				var defer = $.Deferred();
				 $.ajax({
					cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     //async: false,				   
				     success: function(result){
				    	 defer.resolve(result);
			              console.log("告警统计柱状图="+result);
			              //js解析json串
			              var obj = JSON.parse(result);
			              console.log("gj==="+obj.total);//告警系统记录数
			              /*for (var i=0;i<obj.rows.length;i++)
			              {
			                    alert(obj.rows[i].NUM);//统计数据
			                    alert(obj.rows[i].GJTYPE);//统计类别 
			                    alert(obj.rows[i].GJNAME);//统计类别名称
			                    
			              }*/
						for(var i = 0; i < obj.rows.length; i++) {
							data.push(obj.rows[i].NUM);
							dataAxis.push(obj.rows[i].GJNAME);
						}
						//alert(result);
						zhuz(data,dataAxis);
						yn_glsgzb = 1;
					}
	
				});
				 return defer.promise();
			},
			//实时告警向上文字
			warningMsgFunc:function(userid,type,unitid){
				//得到客户下所有站点的告警列表
			    //unitid客户的单位id，单位id为空时调用所有告警列表，如var url="/bigscrenn/getWarningUserList?unitid="
			    var url="/bigscrenn/getWarningUserList?unitid=";
			    var defer = $.Deferred();
				 $.ajax({
				     cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     //async: false,				   
				     success: function(data){
				    	 defer.resolve(data);
	                       //alert(data);
				    	   console.log("告警信息 data = "+data);
	                       //js解析json串
	                       var obj = JSON.parse(data);
	                       //alert(obj.total);//记录数
	                       
	                       var alarmInfoMsg_ul = document.getElementById("alarmInfoMsg_ul");//实时告警推送
			               localStorage.setItem("gjDataNum",obj.rows.length);//用于弹框
	                       if($("#secondPageMsg_ul li").length>0){
	                    	   $("#secondPageMsg_ul").empty();
	                       }
	                       
	                       //for (var i=0;i<obj.rows.length;i++)
	                       for (var i=0;i<(obj.rows).slice(0,9).length;i++)
	                       {
	                             //alert(obj.rows[i].CID);   //告警id
	                             //alert(obj.rows[i].WTITLE);//告警标题
	                             //alert(obj.rows[i].WCONTENT);//告警内容
	                             //alert(obj.rows[i].GJTYPE);//告警类别，0一般事件1报警事件 2 跳闸事件
	                             //alert(obj.rows[i].CDATE);  //告警时间
	                    	     //$("#secondPageMsg_ul").append("<li class='specHomeGjxx'><p><a href='javascript:;' title="+obj.rows[i].CDATE+'>' + obj.rows[i].CDATE + "<a style='display: none;'>"+obj.rows[i].GJTYPE+"</a><a href='javascript:;' title="+obj.rows[i].WTITLE+'>' + obj.rows[i].WTITLE + "<span style='display: none;'>"+ obj.rows[i].GJTYPE+"</span></a><a style='display: none;'>"+obj.rows[i].WCONTENT+"</a></p></li>");
				            	 $("#secondPageMsg_ul").append("<li><p><a href='javascript:;' title="+obj.rows[i].CDATE+'>' + obj.rows[i].CDATE +"<a style='display: none;'>"+obj.rows[i].GJTYPE+"</a>"+"<a href='javascript:;' title="+obj.rows[i].WTITLE+'>' + obj.rows[i].WTITLE +""+ "<span style='display: none;'>&nbsp;&nbsp;&nbsp;"+ obj.rows[i].GJTYPE+"</span></a><a style='display: none;'>"+obj.rows[i].WCONTENT+"</a></p></li>");
				            	 
	                       }
	                       setTrColrFunc();  
	                      // alert($("#secondPageMsg_ul li").length);
	                       
	                       $("#secondPageMsg_ul li").click(function(){
	                    	   var inedx = $(this).index();
	        					//alert("inedx = "+inedx);
	        					layer.open({
	        						title:"告警信息",
	        						center:"center",
	        						type: 1,
	        					    skin: 'layui-layer-rim', //加上边框
	        						area: ['calc(30% - 50px)', '350px'], //宽高
	        						//content: 'html内容',
	        						content: '<div style="padding:20px;">'+$(this).html()+'</div>',
	        					});
	        					$(".layui-layer-rim p a").css({
		       						'color':'#fff',
		       						'display':'block',
		       						'fontSize':'14px',
		       						'lineHeight':'1.3rem'
		       					});
		        					$(".layui-layer-rim").css({
		       						'border':'none',
		       						'background':'#0055b3'
		       					});
	        					$(".layui-layer-rim a.layui-layer-ico").text('×').css({
	        						'color':'#fff',
	        						'fontSize':'2rem',
	        						'margin-top': '-15px',
	        						'background':'none'
	        					});
	        					
	        					$(".layui-layer-rim .layui-layer-title").css({'background':'#0055b3','color':'#fff',});
	                       })
	                       yn_gjxx = 1;
	                       //报警
	                       if(obj.total>0){
	                    	   $("#audio-div").empty()
	                    	   $("#audio-div").append('<audio controls autoplay hidden><source src="warn.wav" type="audio/mpeg"></audio>'+
	                    			   '<audio controls autoplay hidden><source src="warn.mp3" type="audio/mpeg"></audio>');
	                       }
				     }
			     });
				 return defer.promise();    
			},
			
			//判断方法走成功是否，否则再次调用
			duanduan:function(){
				setTimeout(function(){
					//alert("yn_yhzb = "+yn_yhzb);
					if(yn_yhzb == 0){
						vm.userNumFunc(this.userid);
					}
					if(yn_glsgzb == 0){
						vm.alarmTongjifunc(this.userid,this.unitID);
					}
					if(yn_gjxx == 0){
						vm.warningMsgFunc(this.userid,this.unitID);
					}
				},4000)
			},
			//定时刷新
			shuaxin:function(){
				setInterval(function(){
					vm.userNumFunc(this.userid);
					vm.alarmTongjifunc(this.userid,this.unitID);
					vm.warningMsgFunc(this.userid,this.unitID);
				},30000)
			}
			
		}
	})
}
//过滤后的站点（用户）结束
function zhuz(dataArr,dataAxis) {
	
	//alert("告警统计柱状图data="+dataArr);
	var myBarChart = echarts.init(document.getElementById("barID"));
	var myBarOption = {
			title: {
				text: '各类事故占比',
				left: 'center',
				show:false,
				y: '2%',
				textStyle: {
					// 文字颜色
					color: '#fff',
					// 字体风格,'normal','italic','oblique'
					fontStyle: 'normal',
					// 字体粗细 'normal','bold','bolder','lighter',100 | 200 |
					// 300 | 400...
					fontWeight: '100',
					// 字体系列
					fontFamily: 'sans-serif',
					// 字体大小
					　　　　fontSize: 20
				}
			},
			tooltip: {
				trigger: 'axis',
				axisPointer: { // 坐标轴指示器，坐标轴触发有效
					type: 'shadow' ,// 默认为直线，可选为：'line' | 'shadow'
				}
			},
			grid: {
				left: '2%',
				right: '2%',
				bottom: '-4%',
				top: '15%',
				containLabel: true
			},
			xAxis: {
				data: dataAxis,
				axisLabel: {
					inside: false,
					textStyle: {
						color: '#fff',
						fontSize: '14'
					},
					interval: 0,
					rotate: "40"
				},
				axisTick: {
					show: false
				},
				axisLine: {
					show: true,
					lineStyle: {
						color: '#fdd',
						color: "rgba(255,255,255,.1)",
						width: 1,
						type: "solid"
					}
				},
				z: 240
			},
			yAxis: {
				axisLine: {
					show: true,
					lineStyle: {
						color: "rgba(255,255,255,.1	)",
						width: 1,
						type: "solid"
					},
				},
				axisTick: {
					show: false
				},
				axisLabel: {
					textStyle: {
						color: '#fff',
						fontSize: '15'
					}
				},
				splitLine: {// 横轴线
					lineStyle: {
						color: "rgba(255,255,255,.1)",
					}
				}
			},
			dataZoom: [{
				type: 'inside'
			}],
			series: [{ // For shadow
					name: "",
					type: 'bar',
					barWidth: '15%', // 柱子宽度
					itemStyle: {
						normal: {
							color: 'rgba(0,0,0,0.05)'
						}
					},
					barGap: '-100%',
					barCategoryGap: '60%',
					//data: dataShadow,
					animation: false
				},
				{
					name: "",
					type: 'bar',
					itemStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(
								0, 0, 0, 1, [{
										offset: 0,
										color: '#205BCF'
									},
									{
										offset: 0.5,
										color: '#188df0'
									},
									{
										offset: 1,
										color: '#0FEB8B'
									}
								]
							),
							barBorderRadius: 50,
						},
						emphasis: {
							/* 柱状体颜色 */
							color: new echarts.graphic.LinearGradient(
								0, 0, 0, 1, [{
										offset: 0,
										color: '#205BCF'
									},
									{
										offset: 0.7,
										color: '#2378f7'
									},
									{
										offset: 1,
										color: '#0FEB8B'
									}
								]
							),
							barBorderRadius: 50,
						}
					},
					data: dataArr
				}
			]
		};
		myBarChart.setOption(myBarOption);
		$(document).ready(function() {
			myBarChart.resize();
		});
		window.addEventListener("resize", function() {
			myBarChart.resize();
		})
}
// 柱状图结束
//覆盖面积饼状图
function bingFunc(dataArr) {
	//alert("覆盖面积饼状图data="+dataArr);
	var myPieChart = echarts.init(document.getElementById("pieID"));
	var barOption = {
		title: {
			text: '覆盖面积',
			x: 'center',
			y: '3%',
			textStyle: {
				// 文字颜色
				color: '#fff',
				// 字体风格,'normal','italic','oblique'
				fontStyle: 'normal',
				// 字体粗细 'normal','bold','bolder','lighter',100 | 200
				// | 300 | 400...
				fontWeight: '100',
				// 字体系列
				fontFamily: 'sans-serif',
				// 字体大小
				　　　　fontSize: 20
			}

		},
		legend: {
			orient: 'horizontal',// vertical
			left: 'center',
			bottom: '3%',
			itemGap: 12,
//			data: ,
			textStyle: {
				// 文字颜色
				color: '#fff',
				// 字体风格,'normal','italic','oblique'
				fontStyle: 'normal',
				// 字体粗细 'normal','bold','bolder','lighter',100 | 200
				// | 300 | 400...
				fontWeight: '100',
				// 字体系列
				fontFamily: 'sans-serif',
				// 字体大小
				　　　　fontSize: 12
			}
		},
		tooltip: {
			trigger: 'item',
			formatter: "{a} <br/>{b} : {c} ({d}%)"
		},
		series: [{
			name: '访问来源',
			type: 'pie',
			radius: ['0%','50%'],
			center: ['50%', '45%'],
			label: {
				normal: {
					show:false,
					//formatter: '{b}:{c}: ({d}%)',
					formatter: '{c} ({d}%)',////饼图边的脚数据
					textStyle: {
						fontWeight: 'normal',
						fontSize: 12
					}
				}
			},
			data: dataArr,
			itemStyle: {
				normal: {
					color: function(params) {
						// 自定义饼图颜色
						var colorList = [
							'#20B9CF', '#6FC9D6', '#08A0B7', '#205BCF', '#5883D8',
							'#3EABFF', '#0AB2E4', '#20CC98', '#33B565', '#0CB2E4'
						];
						return colorList[params.dataIndex]
					}
				},
				emphasis: {
					shadowBlur: 10,
					shadowOffsetX: 0,
					shadowColor: 'rgba(0, 0, 0, 0.5)'
				}
			}
		}]
	};
	myPieChart.setOption(barOption);
	$(document).ready(function() {　　
		myPieChart.resize();

	})
	window.addEventListener("resize", function() {　　
		myPieChart.resize();
	});
}
// 覆盖面积饼状图end

// 用户数饼状图
//用户数饼状图
function JG_pieFunc(dataArr) {
	//alert("二级用户数饼状图data="+JSON.stringify(dataArr));
	var mybaojingChart = echarts.init(document.getElementById("homeUserNumberID"));
	var bjOption = {
			title: {
				show:false,
				text: '主要功能用户占比及分类占比',
				x: 'center',
				y: '1%',
				textStyle: {
					// 文字颜色
					color: '#fff',
					// 字体风格,'normal','italic','oblique'
					fontStyle: 'normal',
					// 字体粗细 'normal','bold','bolder','lighter',100 | 200
					// | 300 | 400...
					fontWeight: '100',
					// 字体系列
					fontFamily: 'sans-serif',
					// 字体大小
					fontSize: "20"
				}
			},
			legend: {
				orient: 'horizontal',// vertical
				left: 'center',
				y: 'bottom',
				itemGap: 12,
				//data: ,
				textStyle: {
					// 文字颜色
					color: '#fff',
					// 字体风格,'normal','italic','oblique'
					fontStyle: 'normal',
					// 字体粗细 'normal','bold','bolder','lighter',100 | 200
					// | 300 | 400...
					fontWeight: '100',
					// 字体系列
					fontFamily: 'sans-serif',
					// 字体大小
					　　　　fontSize: 12
				}
			},
			tooltip: {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)"
			},
			series: [{
				name: '用户数',
				type: 'pie',
				radius: '50%',
				center: ['50%', '35%'],
				label: {
					normal: {
						show:false,
                        //formatter: '{b}:{c}: ({d}%)',
						formatter: '{c} ({d}%)',////饼图边的脚数据
						textStyle: {
							fontWeight: 'normal',
							fontSize: 12
						}
					}
				},
				data: dataArr,
				itemStyle: {
					normal: {
						color: function(params) {
							// 自定义饼图颜色
							var colorList = [
								'#20B9CF', '#33B565',
								'#3EABFF', '#0AB2E4', '#6FC9D6', '#08A0B7',
								'#205BCF', '#5883D8', '#20CC98', '#0CB2E4'
							];
							return colorList[params.dataIndex]
						}
					},
					emphasis: {
						shadowBlur: 10,
						shadowOffsetX: 0,
						shadowColor: 'rgba(0, 0, 0, 0.5)'
					}
				}
			}]
		};
		mybaojingChart.setOption(bjOption);
		$(document).ready(function() {　　
			mybaojingChart.resize();

		})
		window.addEventListener("resize", function() {　　
			mybaojingChart.resize();
		});

}

// 饼状图end
// 设备分类占比 开始
function sheBeiFenLeiFunc() {
	var sheBeiData = [];
	// 无调用参数
    var url="/bigscrenn/getDeviceStatistics";
    var defer = $.Deferred();
	 $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     //async: false,				   
	     success: function(data){
	    	 defer.resolve(data);
            //alert(data);
           // js解析json串
           var obj = JSON.parse(data);
           console.log("设备分类数据==："+data);// 数据
           console.log("设备分类记录数==："+obj.total);// 记录数
           /*
			 * for (var i=0;i<obj.rows.length;i++) {
			 * alert(obj.rows[i].NUM);//设备数 alert(obj.rows[i].NAME);//统计类别名称
			 *  }
			 */
           if(obj != null && obj.rows.length > 0) {
				for(var i = 0; i < obj.rows.length; i++) {
					var nl = {"name":obj.rows[i].NAME+obj.rows[i].NUM,"value":obj.rows[i].NUM};
					sheBeiData.push(nl);
				}
           }
            
           //shebeiShow();
	     }
     });
     function shebeiShow(){
    	 var equipmentChart = echarts.init(document.getElementById("equipment"));
    		var equipment_option = {
    			title: {
    				text: '设备分类比',
    				x: 'center',
    				y: '3%',
    				textStyle: {
    					// 文字颜色
    					color: '#fff',
    					// 字体风格,'normal','italic','oblique'
    					fontStyle: 'normal',
    					// 字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 |
    					// 400...
    					fontWeight: '100',
    					// 字体系列
    					fontFamily: 'sans-serif',
    					// 字体大小
    					fontSize: 20
    				}
    			},
    			tooltip: {
    				trigger: 'item',
    				formatter: "{a} <br/>{b} : {c} ({d}%)"
    			},
    			legend: {
    				orient: 'horizontal',// vertical
    				left: 'center',
    				bottom: '3%',
    				itemGap: 10,
    				// data: ['变压器', '串并联谐振', '互感器校验测试', '油化分析系列', '其它电力测试仪器'],
    				textStyle: {
    					// 文字颜色
    					color: '#fff',
    					// 字体风格,'normal','italic','oblique'
    					fontStyle: 'normal',
    					// 字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 |
    					// 400...
    					fontWeight: '100',
    					// 字体系列
    					fontFamily: 'sans-serif',
    					// 字体大小
    					　　　　fontSize: 12
    				}
    			},
    			series: [{
    				name: '设备分类',
    				type: 'pie',
    				radius: ['0%', '50%'],
    				center: ['50%', '45%'],
    				data:sheBeiData,
    				label:{
    					normal:{
    						show:false,
    						formatter:"{c} ({d}%)"
    					}
    				},
    				itemStyle: {
    					normal: {
    						color: function(params) {
    							// 自定义饼图颜色
    							var colorList = [
    								'#6778F4', '#0FEB8B', '#DE67F4', '#08A0B7',
    								'#21E0DA', '#33B565',
    							];
    							return colorList[params.dataIndex]
    						}
    					}

    				}
    			}]
    		};
    		equipmentChart.setOption(equipment_option);
    		$(document).ready(function() {
    			equipmentChart.resize();
    		});
    		window.addEventListener("resize", function() {
    			equipmentChart.resize();
    		})
     };
     return defer.promise();
}
// 设备分类占比 结束
$(function() {
	var userID = localStorage.getItem("homeid");
	console.log("第二页获取登录用户ID="+userID);
	sheBeiFenLeiFunc();// 设备分类占比
})


// 用户选择
function selectSH(id) {
	// vueFunc();//调用vueFunc()
	var te = $("#SH").attr("btnType");
	if(te == "隐藏") {
		$("#SH").attr("btnType", "显示");
		$("#selectBox").fadeIn(600, function() {
			$("#selectBox").css("display", "block")
		})
	}
	if(te == "显示") {
		$("#SH").attr("btnType", "隐藏");
		$("#selectBox").fadeOut(600, function() {
			$("#selectBox").css("display", "none")
		})
	}
}
// 用户选择结束

//设置session参数
function setSessionfunc(typeid,zid,tanKuang,danweiID){
	//设置当前用户的session值
    //typeid 系统分类id (比如对应前端八大类), zid 当前用户的站点id
	var url="/bigscrenn/setUserSession?typeid="+typeid+"&zid="+zid+"&cid="+tanKuang+"&cid1="+danweiID;
    $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
              console.log(data,'参数');         
	     }
    		
    });	
}

// 点击详情开始
function openLayerFunc(id){
	var tHeight = 0;
	var windowH = $(window).height();     //浏览器时下窗口可视区域高度
	var dataLength = localStorage.getItem("upDataNum");
	var gjDataLength = localStorage.getItem("gjDataNum");
	
	//-----
	var tsid2 = $("#tuisong2").attr("id");
	var SSGJ2 = $("#shishiGJ2").attr("id");
	console.log("推送消息id="+tsid2+'--'+"实时告警id=:"+SSGJ2);
	var area = [];
	var title = '';
	if(id == tsid2){//当点击推送消息的详情时的操作
		setSessionfunc('','',tsid2);
		if(dataLength){
			tHeight = dataLength*37+110;
			//alert("tHeight="+tHeight);
			if(tHeight>windowH){
				tHeight=windowH;
			}
		}else{
			tHeight = 138;
		}
		area = ['1000px',tHeight.toString()+'px'];
		ifFunc('信息发布',area,tsid2);
	}
	if(id == SSGJ2){//当点击实时告警推送的详情时的操作
		setSessionfunc('','',SSGJ2);
		if(gjDataLength && gjDataLength > 0){
			tHeight = gjDataLength*37+105;
			//alert("tHeight="+tHeight);
			if(tHeight>windowH){
				tHeight=windowH-400;
			}
		}else{
			tHeight = 138;
		}
		area = ['1020px',tHeight.toString()+'px'];
		
		ifFunc('实时告警详情',area,SSGJ2);
	}
	
	function ifFunc(title,area,ID){
		layer.open({
			type: 2,
			title: false,
			//title:'实时告警详情',
			title:title,
			center:"center",
			closeBtn: 1,
			area: ['1010px', '500px'],
			//area: area,
			shadeClose: true,
			skin:"myskin",
			scrollbar:false,
			content: 'tanKuang.html',
			resize:false,//是否允许拉伸
		})
	}
	$('.myskin').css({
		'background':'#07256b'
	})
	$(".myskin a.layui-layer-ico").text('×').css({
		'color':'#fff',
		'fontSize':'2rem',
		'margin-top': '-15px',
		'background':'none'
	});
	
	$(".layui-layer-title").css({'color':'#fff',});
	
}

//判断告警信息弹框的事件类型 设置行颜色
function setTrColrFunc(){
	var trNum = $(".gaojingUl li");
	//alert($(".gaojingUl li").eq(1).find('p').find('span').text());
	
	for(var k=0;k<trNum.length;k++){
		var tdStr1 = $(".gaojingUl li").eq(k).find('p').find('span').text();
		if(tdStr1.indexOf("报警事件") >= 0 ) {
		    $(".gaojingUl li").eq(k).find('a').css('color','orange')
		}if(tdStr1.indexOf("跳闸事件") >= 0 ) {
		    $(".gaojingUl li").eq(k).find('a').css('color','red')
		}if(tdStr1.indexOf("一般事件") >= 0 ) { 
		    $(".gaojingUl li").eq(k).find('a').css('color','#0feb8b')
		}
	}
}
